<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){
       // dump($list);exit;
        $domain_id = C('DEFAULT_SITE_ID');
        $p = I('p',1);
        $p = intval($p);
       /*  if(is_file($f=HTML_PATH.'index.html') && (NOW_TIME-filemtime($f)<36000)){
            include $f;
            exit;
        } */
        //文章基础信息表
        $document = D('Document');
      	//文章分类表 ：category_tags=1
        $category = D('category');
        $recommend = $document->position([4,5,6]);
        if($recommend){
            $recommend=getNameCount($recommend,'Document','pin_yin');
        }
       
        $lists = $document->getSiteArticleList($domain_id,$p,10);
        //增加pin_yin属性的统计
        $lists=getNameCount($lists,'Document','pin_yin');
        $articleId=array_column($lists, 'id');
        //$category_tag=D('Tags')->getTags($articleId);//获取标签
        $this->_listLeftInfo($articleId);//获取标签
        $categoryAll = $category->getChildrentitle(1);//获取分类

        $document_count = $document->getSiteArticleCount($domain_id);
        
        $page = ceil($document_count/10)+1;
        if ($p >= $page){
            redirect('/');
        }
        $ad=M('AdvertiseContent');
        //获取广告内容1:Slide幻灯片2:Home_left首页左3:Home_right首页右4:Home_bottom首页中间5:Home_bottom首页底部6:Details_top详情顶部
        $topAd=$ad->where('category_id=1')->order('sort')->select();
        
        $rightAd=$ad->where('category_id=3')->order('sort')->select();
        $footerAd=$ad->where('category_id=5')->order('sort')->find();
        $centerAd=$ad->where('category_id=4')->page($p,6)->order('sort')->select();
        $centerAdAll=$ad->where('category_id=4')->limit(6)->order('sort')->select();
        if($p>1){
            $len=sizeof($centerAd);
            for($i=1;$i+$len<=6;$i++){
                $centerAd[$len+$i-1]=$centerAdAll[$i+$len-1];
            }
        }
        $this->header();//头部内容
        //seo
        $header_tag=array_column($category_tag, "tag_name");
        $header_tag=implode($header_tag, '.');
        C('WEB_SITE_TITLE','专业服装搭配_穿衣打扮技巧_服装服饰新闻资讯_全球时尚潮流趋势_衣商网');
        C('WEB_SITE_KEYWORD',C('TITLE').'为您提供专业穿衣搭配技巧，引领穿衣打扮时尚潮流，教您穿出气质，搭出风采，每天更新服装行业资讯，是专业流行服装搭配资讯网');
        C('WEB_SITE_DESCRIPTION','服装搭配,穿衣技巧,时尚资讯,穿搭指南');
        
       
        //dump($rightAd);exit;
        $this->assign('topAd',$topAd);
        $this->assign('footerAd',$footerAd);
        $this->assign('centerAd',$centerAd);
        $this->assign('rightAd',$rightAd);
        
        $newDoc=$document->getSiteNewArticleList($domain_id);//最新资讯
        $newDoc=getNameCount($newDoc,'Document','pin_yin');//对pin_yin属性进行统计
        
        $this->assign('newDoc',$newDoc);
        $this->assign('lists',$lists);//列表
        $this->assign('page',$page);//分页
        $this->assign('p',$p);//当前页
        $this->assign('category',$categoryAll);//分类
        //$this->assign('tags',$category_tag);//标签
        
        $this->assign('recommend',$recommend);//首页推荐文章
        
       //echo  $this->buildHtml('index.html');
       $this->_display();
    }
   public function addPin(){

        //给文章标签数据库增加拼音
        //给每个文章的标题增加拼音
       $list=M('Tags')->where(array('id'=>array('gt',38788)))->select();
       foreach ($list as $k=>$v){
           //dump($v[title]);exit;
           $list[$k]['pinyin']=substr(getPinYin($v[tag_name]),0,20);
           $data['name']=$list[$k]['pinyin'];
           $re=M('Tags')->where('id='.$v['id'])->save($data);
       }
       dump($re);
    }
}